<?php
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::namespace('Api')->prefix('v1')->middleware(['cors', 'auth:api', 'auth.token'])->group(function () {

    Route::post('chats', "ChatsController@store");
    // 获取验证码
    Route::post('yzm', "LoginController@getYZM")->name('login.yzm');
    // 通过验证码绑定手机号码
    Route::post('bind-phone', "LoginController@bindPhone")->name('login.bind-phone');

    // 获取用户基本信息
    Route::get('users/profile', "UsersController@profile")->name('users.show');
    // 修改用户基本信息
    Route::put('users', "UsersController@update")->name('users.update');
    // 上传用户头像
    Route::post('users/upload-avatar', "UsersController@uploadAvatar")->name('users.upload.avatar');

    // 获取地址列表
    Route::get('user-addresses', "UserAddressesController@index")->name('user-address.index');
    // 默认收货地址
    Route::get('user-addresses/default', "UserAddressesController@defaultShow")->name('user-address.default.show');
    // 获取地址详情
    Route::get('user-addresses/{userAddress}', "UserAddressesController@show")->name('user-address.show');
    // 添加地址
    Route::post('user-addresses', "UserAddressesController@store")->name('user-address.store');
    // 修改地址
    Route::put('user-addresses/{userAddress}', "UserAddressesController@update")->name('user-address.update');
    // 删除地址
    Route::delete('user-addresses/{userAddress}', "UserAddressesController@destroy")->name('user-address.destroy');
    // 省市区三级联动列表
    Route::get('areas', "AreasController@index")->name('areas.index');

    // 商品列表
    Route::get('products', 'ProductsController@index')->name('product.index');
    // 猜你喜欢商品列表
    Route::get('products/guess-you-like', 'ProductsController@guessYouLikeIndex')->name('product.guess-you-like');
    // 商品收藏列表
    Route::get('products/favour', 'ProductsController@favourites')->name('product.favourites');
    // 收藏商品 这里应该products/{product}/favour好一点, 但由于前段是我随便找的, 真的不想改前端了
    Route::post('products/favour/{product}', "ProductsController@favour")->name('product.favour');
    // 取消商品收藏  这里应该products/{product}/disfavour, 但由于前段是我随便找的, 真的不想改前端了
    Route::post('products/disfavour/{product}', "ProductsController@disfavour")->name('product.disfavour');
    // 商品详情
    Route::get('products/{product}', 'ProductsController@show')->name('product.show');

    // 购物车列表
    Route::get('cart', "CartController@index")->name('cart.index');
    // 添加商品到购物车中
    Route::post('cart', "CartController@add")->name('cart.add');
    // 修改某个商品的数量
    Route::put('cart/edit', "CartController@edit")->name('cart.edit');
    // 从购物车中移除某个商品
    Route::delete('cart/{productSku}', "CartController@remove")->name('cart.remove');
    // 从购物车中移除某些商品
    Route::delete('cart', "CartController@destroy")->name('cart.destroy');
    // 购物车列表
    Route::get('cart/num', "CartController@cartNum")->name('cart.num');

    // 用户创建订单
    Route::post('orders', "OrdersController@store")->name('order.store');
    // 显示订单详细信息
    Route::get('orders/{order}', "OrdersController@show")->name('order.show');
    // 显示订单简单信息
    Route::get('orders/simple/{order}', "OrdersController@simpleShow")->name('order.simple_show');
    // 用户订单列表
    Route::get('orders', "OrdersController@index")->name('order.index');
    // 预加载订单相关信息
    Route::post('orders/preview', "OrdersController@preview")->name('order.preview');
    // 申请退款 这里orders/{order}/apply_refund 比较好, 但是前端我不想改了
    Route::post('orders/apply_refund/{order}', "OrdersController@applyRefund")->name('order.apply_refund');
    // 订单确认收货
    Route::post('orders/receipt', "OrdersController@receipt")->name('order.receipt');
    // 搜索订单
    Route::post('orders/search-by-no', "OrdersController@searchOrderByNo")->name('order.search_order_by_no');
    // 订单评论项: 多order_item_id + 多评论
    Route::post('orders/review', "OrdersController@review")->name("order.review");
//    Route::post('orders/review2', "OrdersController@review2")->name("order.review2");

    // 支付宝支付前端回调
    Route::get('payment/alipay/return', 'PaymentController@alipayReturn')->name('payment.alipay.return');

    // 商品分类列表
    Route::get('categories', 'CategoriesController@index')->name('categories.index');
    Route::get('top-categories', 'CategoriesController@topIndex')->name('top-categories.index');

    // 获取优惠券列表
    Route::get('coupon-codes', 'CouponCodesController@index')->name('coupon.index');
    // 获取我的优惠券列表
    Route::get('coupon-codes/user', 'CouponCodesController@indexUser')->name('coupon.index_user');
    // 领取优惠券
    Route::post('coupon-codes/receive', 'CouponCodesController@receive')->name('coupon.receive');
    // 优惠券详情
    Route::get('coupon-codes/{code}', 'CouponCodesController@show')->name('coupon-codes.show');

    // 支付宝支付
    Route::post('payment/alipay', 'PaymentController@payByAlipay')->name('payment.alipay');

    // 获取广告列表
    Route::get('adv', 'AdvertisementsController@index')->name('adv.index');

});

Route::namespace('Api')->prefix('v1')->middleware('cors')->group(function () {
    // 微信授权登录
    Route::middleware('wechat.oauth')->get('wechat/h5-login', 'LoginController@weChatH5Login');
    // 手机号码 + 密码登录
    Route::post('login', "LoginController@defaultLogin")->name('login.default-login');
    // 手机号码 + 验证码登录
    Route::post('yzm-login', "LoginController@yzmLogin")->name('login.yzm-login');
    // 根据refreshToken重新生成api_token
    Route::post('refresh-token', "LoginController@refreshToken")->name('login.refresh-token');
});

Route::namespace('Api')->prefix('v1')->group(function () {
    // 支付宝支付后端回调
    Route::post('payment/alipay/notify', 'PaymentController@alipayNotify')->name('payment.alipay.notify');
    // webApp首页
    Route::get('index', 'IndexController@index')->name('index.index');
});

